window.onload=function() {
    var phone = document.querySelector("#phone_input")
    var number = document.querySelector("#num_input")
    var btn = document.querySelector(".getnumber")
    var btn2 = document.querySelector(".reg-button")
    var e = document.querySelector('.error');
    // background: -webkit-linear-gradient(left, #ff9900,#ff5000);
    
 
    btn.addEventListener("click",function() {
        var str = phone.value
        if(str.length==11) {
            var str1 = str.slice(0,3)
            if(str1=='133' || str1=='135' || str1=='153' || str1=='136' || str1=='130' || str1=='131' || str1=='138') {
                btn.style.color='#cccccc'
                var n = 59;
                btn.innerHTML='重发验证码('+ n-- +')'
                var timer = setInterval(function name(params) {
                    btn.innerHTML='重发验证码('+ --n +')'
                    if(n==0) {
                        clearTimeout(timer);
                        btn.style.color='#ff5000'
                        btn.innerHTML='重发'
                    }
                },1000)
            }else {
                e.style.display='block'
                error();
            }
        }else {
            e.style.display='block'
            error();
        }
    })

    window.addEventListener('keyup',function () {
        var p = phone.value;
        var n = number.value;
        if(p != '' && n != '') {
            btn2.style.background = '-webkit-linear-gradient(left, #ff9900,#ff5000)'
            btn2.style.color = '#ffffff';
            console.log(1);
        }else {
            btn2.style.background = '-webkit-linear-gradient(left, #ffcc80,#ffa880)'
        }
    })
    var error = function() {
        var n = 4;
        var t = setInterval(function () {
            n--;
            if(n==0) {
                e.style.display='none'
                clearTimeout(t);
            }
        },1000)
    }
    
}